#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
"""
@File    :   api.py
@Time    :   2023/11/09 15:19:41
@Author  :   windstarry 
@Version :   1.0
"""
# here put the import lib
from utils.ninja import BaseNinjaAPI as NinjaAPI
from utils.auth import GlobalAuth
from music.router import router as music_router
from system.router import router as system_router


api = NinjaAPI(
    title="DjangoNinja-Music",
    description="使用DjangoNinja构建music管理系统",
    auth=GlobalAuth(),
)

# 统一处理server异常
@api.exception_handler(Exception)
def a(request, exc):
    if hasattr(exc, 'errno'):
        return api.create_response(request, data=[], msg=str(exc), code=exc.errno)
    else:
        return api.create_response(request, data=[], msg=str(exc), code=500)
    



api.add_router("/", music_router, tags=["音乐管理"])
api.add_router("/", system_router, tags=["系统管理"])
